package svc

import (
	"app-api/app/internal/config"
	"app-api/clients/user"
	"app-api/clients/video"
	"github.com/apache/pulsar-client-go/pulsar"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config config.Config
	Redis  *redis.Redis
	//KqPusher *kq.Pusher
	//KqConsumer *kq
	UserRPC  user.UserZrpcClient
	VideoRPC video.Video

	PulsarClient   pulsar.Client
	PulsarConsumer pulsar.Consumer
	PulsarProducer pulsar.Producer
}

func NewServiceContext(c config.Config) *ServiceContext {
	pulsarClient, err := pulsar.NewClient(pulsar.ClientOptions{
		URL: c.Pulsar.URL,
	})
	if err != nil {
		panic("Failed to create client: " + err.Error())
	}

	return &ServiceContext{
		Config:       c,
		Redis:        redis.MustNewRedis(c.GeneralRedis),
		UserRPC:      user.NewUserZrpcClient(zrpc.MustNewClient(c.UserRPC)),
		VideoRPC:     video.NewVideo(zrpc.MustNewClient(c.VideoRPC)),
		PulsarClient: pulsarClient,
	}
}
